﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;

namespace 图书管理系统
{
    class ClaimrecordDao
    {
        public int insert(String ReaderID,String BookNum,String BorrowID)
        {
            SqlConnection conn = new SqlConnection();
            System.DateTime currentTime = new System.DateTime();
            currentTime = System.DateTime.Now;
            String ReplyID = ReaderID + count().ToString();
            String sql1 = "insert into Claimrecord_Table(ReplyID,Reply_time,ReplyState,ReaderID,BookNum,BorrowID) values('"+ReplyID+"','"+currentTime+"','"+"未审核"+"','"+ ReaderID +"','"+BookNum+"','"+BorrowID+"')";
            SqlCommand cmd1 = Dao.SqlConnect(sql1, conn);
            conn.Open();
            if (cmd1.ExecuteNonQuery()>0)
            {
                conn.Close();
                return 1;
            }

            return 0;
        }
        public int count()
        {
            SqlConnection conn = new SqlConnection();
            String sql = "Select count(*) from Claimrecord_Table";
            SqlCommand cmd = Dao.SqlConnect(sql, conn);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            String num = null;
            while(reader.Read())
            {
                num = reader[0].ToString();
            }
            conn.Close();
            return int.Parse(num) + 1;
        }
    }
}
